//const homeData = require('../../antiqueData/antiqueData.js');

var util = require('../../utils/util.js');
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    navigateTitle: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var category = options.category;
    this.data.navigateTitle = category;

    var dataUrl = app.globalData.antiqueBaseUrl +  "topic.html";

    var typeId = util.classifyNum(category);
    util.httpClassify(dataUrl, typeId, this.processData);

    // var categoryData = this.processData(category);
    
  },

  processData: function(category){
    var categoryData = [];
    var showThreeImg = [];
    category.forEach((antique)=>{
      // var avatar = util.avatarImg(antique.user.headImg);
      var subject = antique.imgs;
      var showImg = util.showImg(subject);
      var showThreeImg = showImg.slice(0,3)
      var temp = {
        antiqueId: antique.id,
        avatar: antique.user.headImg,
        nickName: antique.user.name,
        publishTime: antique.times,
        antiqueName: antique.type.name,
        antiqueDesc: antique.content,
        browserNum: antique.views,
        showImg: showThreeImg
      }
      categoryData.push(temp);
    })  
    this.setData({
      categoryData: categoryData
    })
  },

  // 详情页面展示
  onAntiqueTap: function(event){
    var antiqueId = event.currentTarget.dataset.antiqueid;
    wx.navigateTo({
      url: "../detail/detail?id=" + antiqueId 
    })
  },

   // 它的发布
  taPublish: function(event){
    console.log('123');
    var antiqueNickName = event.currentTarget.dataset.nickname;
    wx.navigateTo({
      url: "../thirdPublish/thirdPublish?nickname=" + antiqueNickName 
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    //动态设定导航栏标题的方法
    wx.setNavigationBarTitle({
      title: this.data.navigateTitle,
      success: function (res) {
        //success
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})